﻿using System.Collections.Generic;

namespace ConsoleAppSelectMany
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");

            List<Device> list = new List<Device>();

            list.Add(new Device() { Id = 101, Name = "1号设备", });
            list.Add(new Device() { Id = 102, Name = "2号设备", });
            list.Add(new Device() { Id = 103, Name = "3号设备", });
            list.Add(new Device() { Id = 104, Name = "4号设备", });
            list[0]
                .Points.Add(
                    new Point
                    {
                        PointId = "101-1",
                        Name = "测试1",
                        Value = 50
                    }
                );
            list[0]
                .Points.Add(
                    new Point
                    {
                        PointId = "101-2",
                        Name = "测试2",
                        Value = 50
                    }
                );
            list[1]
                .Points.Add(
                    new Point
                    {
                        PointId = "102-3",
                        Name = "测试3",
                        Value = 50
                    }
                );
            list[1]
                .Points.Add(
                    new Point
                    {
                        PointId = "102-4",
                        Name = "测试4",
                        Value = 50
                    }
                );
            list[1]
                .Points.Add(
                    new Point
                    {
                        PointId = "102-1",
                        Name = "测试1",
                        Value = 20
                    }
                );
            list[2]
                .Points.Add(
                    new Point
                    {
                        PointId = "103-2",
                        Name = "测试2",
                        Value = 3
                    }
                );
            list[3]
                .Points.Add(
                    new Point
                    {
                        PointId = "104-3",
                        Name = "测试3",
                        Value = 40
                    }
                );
            list[3]
                .Points.Add(
                    new Point
                    {
                        PointId = "104-4",
                        Name = "测试4",
                        Value = 40
                    }
                );

            var points1 = list.Select(x => x.Points);

            var allPoints = list.SelectMany(x => x.Points);

            var test = list.SelectMany(x => x.Name);
        }
    }

    /// <summary>
    /// 设备
    /// </summary>
    public class Device
    {
        public int Id { get; set; }

        public string Name { get; set; }

        public List<Point> Points { get; set; }

        public Device()
        {
            Points = new List<Point>();
        }
    }

    /// <summary>
    /// 状态点位
    /// </summary>
    public class Point
    {
        public string PointId { get; set; }

        public string Name { get; set; }

        public int Value { get; set; }
    }
}
